<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文件上传</title>
    <script src="/common/js/jquery-3.2.1.js"></script>
    <script src="/common/js/jquery.form.min.js"></script>
    <script>
     $(function (){
         $("#upload").on("change",function(){
             var domain=document.domain;
             $("#form1").ajaxSubmit({
                 url:"http://"+domain+"/file",
                 success:function (str){
                     $("#upload").val("");
                     alert(str);
                 },
                 error:function (str){
                     alert("error");
                 }
             })
         })
     })
    </script>
    <script>
        $(function (){
           var btn1=document.getElementById("btn1");
           var upload=document.getElementById("upload");
           btn1.onclick=function (){
               upload.click();
           }
        })
    </script>
</head>
<body>
<h1>文件上传</h1>
<form id="form1" method="post" enctype="multipart/form-data">
    <input id="upload" style="display:none" type="file" name="file">
</form>
<input type="button" value="上传文件" id="btn1">
</body>
</html>